package com.dyz.leetcode._11_comprehensiveApplication;

import java.util.HashMap;

public class _01_twoSum {
    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i<nums.length; i++){
            if(map.containsKey(target-nums[i])){
                int index = map.get(target-nums[i]);
                if(index!=i){
                    return new int[]{i, index};
                }
            }
            map.put(nums[i],i);
        }
        return new int[2];

    }

    public static void main(String[] args) {
        int[] arr = new int[]{2,7,11,15};
        new _01_twoSum().twoSum(arr,  9);
    }
}
